package net.oschina.app.adapter.my;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.adapter.BaseRecyclerViewAdapter;
import net.oschina.app.bean.Friend;
import net.oschina.app.databinding.FansItemBinding;
import net.oschina.app.util.UIUtils;

import java.util.List;

/**
 * Created by YL on 2017/4/2.
 */
public class FansAdapter extends BaseRecyclerViewAdapter {
    private List<Friend> flist;

    public FansAdapter(List<Friend> flist) {
        this.flist = flist;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.fans_item,parent,false);
        FansAdapter.FansViewHolder holder = new FansAdapter.FansViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        FansAdapter.FansViewHolder viewHolder = (FansAdapter.FansViewHolder) holder;
        Friend friend = flist.get(position);
        FansItemBinding binding = DataBindingUtil.bind(holder.itemView);
        binding.setFriend(friend);
        int i = friend.getGender() == 1 ? R.drawable.userinfo_icon_male : R.drawable.userinfo_icon_female;
        binding.setImageUrl(UIUtils.getContext().getResources().getDrawable(i));
    }

    @Override
    public int getItemCount() {
        return flist.size();
    }

    public class FansViewHolder extends RecyclerView.ViewHolder {

        public TextView mTextView;

        public FansViewHolder(View itemView) {
            super(itemView);
            mTextView = (TextView) itemView.findViewById(R.id.favorite_tv);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }
    /*@BindingAdapter("image")
    public static void imageLoader(ImageView imageView, int url){
        imageView.setBackgroundResource(url);
    }*/
}
